define(function(require, exports){
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var util = require('util');
	var view  = require('@base/view');
	var input = require('@base/common/input');
	var taglabels = require('@base/taglabels');
	var drop = require('@base/common/drop');

	// 活动名称
	var Name = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': LANG('新建活动_%1', util.date('YmdHis')),
				'width': '40%'
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.name = Name;

	// 复制活动按钮
	var Copy = input.button.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': LANG('从现有活动复制'),
				'class': 'btn btn-default ml20',
				'width': 140
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
			self.getDOM().find('button').attr('id', 'COPY_CAMPAIGN');
		}
	});
	exports.copy = Copy;

	// 简单版-出价方式
	var LitePrice = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignLitePrice',
				'view_model': {
					'showCPC': false
				}

			});
			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var el = self.getDOM();

			$([
				'<div class="M-formConGroup">',
					'<label class="group-label">'+LANG('出价方式：')+'</label>',
					'<div class="group-content">',
						'<span pub-name="wardenStatus" pub-mod="@base/common/input.radio"></span>',
					'</div>',
				'</div>',

				'<div class="M-formConGroup" ms-visible="!showCPC">',
					'<label class="group-label name">'+LANG('出价：')+'</label>',
					'<div class="group-content" >',
						'<span pub-name="chargePrice" pub-mod="@base/common/input.text"></span>',
					'</div>',
				'</div>',

				'<div class="M-formConGroup" ms-visible="showCPC">',
					'<label class="group-label name">'+LANG('优化CPC：')+'</label>',
					'<div class="group-content" >',
						'<span pub-name="targetCpa" pub-mod="@base/common/input.text"></span>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);


			self.buildFromTemplate({
				'wardenStatus': {
					'data': [
						{text: LANG('CPM竞价'), value: 0, 'checked': true},
						{text: LANG('CPC优化'), value: 2}
					],
					'changeEvent': true
				},
				'chargePrice': {
					'placeholder': '0.00',
					'beforeText': '￥',
					'width': '40%',
					'afterText': LANG('元/千次曝光')
				},
				'targetCpa': {
					'placeholder': '0.00',
					'beforeText': '￥',
					'width': '40%',
					'afterText': LANG('元')
				}
			});
		},
		onRadioChange: function(ev){
			if(ev.name == 'wardenStatus') {
				this.vm.$.showCPC = +ev.param.value == 2;
			}
			return false;
		},
		getData: function(){
			var self = this;
			var cs = self.$;
			var WardenStatus = +self.$.wardenStatus.getData();
			var ChargePrice = 0;
			var TargetCpa = 0;

			if(WardenStatus === 0){
				ChargePrice = Math.round(+cs.chargePrice.getValue()*100)/100;
			}else{
				TargetCpa = Math.round(+cs.targetCpa.getValue()*100)/100;
			}

			var data = {
				// 出价方式
				WardenStatus: WardenStatus,
				// 最高出价保存
				ChargePrice: ChargePrice,
				TopPrice: ChargePrice,
				// 自动优化
				TargetCpa: TargetCpa,
			};

			return data;
		},
		setData: function(data){
			var self = this;
			if(data){
				self.$.wardenStatus.setData(data.WardenStatus);
				self.$.chargePrice.setValue(data.ChargePrice);
				self.$.targetCpa.setValue(data.TargetCpa);
				if(data.WardenStatus === 0){
					self.vm.$.showCPC = false;
				}
			}
			return self;
		},
		reset: function(){
			var self = this;
			self.$.wardenStatus.setData(0);
			self.$.chargePrice.setValue('');
			self.$.targetCpa.setValue('');
			self.vm.$.showCPC = false;
			return self;
		}
	});
	exports.litePrice = LitePrice;

	// 出价方式
	var Price = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'width': '40%'
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.price = Price;

	// 最高出价
	var TopPrice = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': '',
				'width': '40%',
				'placeholder': '0.00',
				'beforeText': '￥',
				'afterText': LANG("元/千次曝光")
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.topPrice = TopPrice;

	// 平均CPM
	exports.avgPrice = TopPrice;

	// 优化单价
	var TargetCpa = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': '',
				'width': '40%',
				'placeholder': '0.00',
				'beforeText': '￥',
				'afterText': LANG("元")
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.targetCpa = TargetCpa;

	// 总预算
	var TotalBudget = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': '',
				'width': '40%',
				'placeholder': '0.00',
				'beforeText': '￥',
				'afterText': LANG("元")
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.totalBudget = TotalBudget;

	// 每日预算
	var Budget = input.text.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': '',
				'width': '40%',
				'placeholder': '0.00',
				'beforeText': '￥',
				'afterText': LANG("元")
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.budget = Budget;

	// 投放速度
	var GovernorStatus = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('快速'), value: 0, 'checked': true},
					{text: LANG('匀速'), value: 1}
				]
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.governorStatus = GovernorStatus;

	// 频次控制
	var FrequencyFilters = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formFrequencyFilters mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/frequency.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.reset().setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.frequencyFilters = FrequencyFilters;

	// 重定向
	var Pdmp = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				// 活动类型 1 RTB 2代理 3直投，4移动 上级模块传入
				// 'channelType': 4,
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定人群'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			var c = self.getConfig();
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			self.$type = c && c.channelType || 1;
			var doms = self.$doms = {
				con: $('<div class="M-formPdmp mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/loadOnVisible.base', {
					'module_name': 'pdmp',
					'layout': {
						'module': 'campaign/modules/character.newPDMP',
						'url': 'PDMP/characters',
						'param': {
							'Type': self.$type,
							'runstatus': 1
						}
					},
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			var self = this;
			var character = data;
			if(character){
				var has;
				if(self.$type == 1) {
					var characterIp = character.Ip || {};
					var characterCookie = character.Cookie || {};
					var hasIpInclude = characterIp.Include && characterIp.Include.length;
					var hasIpExclude = characterIp.Exclude && characterIp.Exclude.length;
					var hasCookieInclude = characterCookie.Include && characterCookie.Include.length;
					var hasCookieExclude = characterCookie.Exclude && characterCookie.Exclude.length;
					has = hasIpInclude || hasIpExclude || hasCookieInclude || hasCookieExclude;
				}
				else {
					var characterDevice = character.Device || {};
					var hasDeviceInclude = characterDevice.Include && characterDevice.Include.length;
					var hasDeviceExclude = characterDevice.Exclude && characterDevice.Exclude.length;
					has = hasDeviceInclude || hasDeviceExclude;
				}

				this.$.detail.setValue(character);
				if(has){
					this.list[1].click();

				}else{
					this.list[0].click();
				}

			}
			return self;
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getValue();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.pdmp = Pdmp;

	// 投放日期
	var Date = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'class': 'M-formDate'
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			var doms = self.$doms = {
				start: $('<div class="dib"/>').appendTo(el),
				split: $('<div class="dib mg5"/>').appendTo(el),
				end: $('<div class="dib"/>').appendTo(el)
			}
			self.createAsync('startTime', '@base/common/date.datePickerNew', {
				target: doms.start,
				value: util.date('Y-m-d'),
				buttons: null,
				width: 120
			});

			$('<span/>').text(LANG('至')).appendTo(doms.split);

			self.createAsync('endTime', '@base/common/date.datePickerNew', {
				target: doms.end,
				width: 120
			});
		},
		getData: function(){
			var data = {
				StartTime: 0,
				EndTime: 0
			}
			if(this.get('startTime')){
				data.StartTime = this.get('startTime').getData();
			}
			if(this.get('endTime')){
				data.EndTime = this.get('endTime').getData() || 0;
			}

			return data;
		},
		setData: function(data){
			if(data){
				this.get('startTime').setData(data.StartTime);
				this.get('endTime').setData(data.EndTime);
			}
			return this;
		},
		reset: function(){
			this.get('startTime').setData(util.date('Y-m-d'));
			this.get('endTime').setData(null);
			return this;
		}
	});
	exports.date = Date;

	// 日程设置time
	var Time = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('全天候展示广告'), value: 1, 'checked': true},
					{text: LANG('指定时间'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formTime mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/timeZone.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data && data.Type !==1){
				this.list[1].click();
				this.$.detail.setData(data.DayHour);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			var self = this;
			var data = {};
			if (self.list[0].prop('checked')){
				data.Type = 1;
			}else {
				data.Type = 2;
			}
			data.DayHour = self.$.detail.getData();
			return data;
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.time = Time;

	// 投放地区zone
	var Zone = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formTime mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/newZone.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data && data.length){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.zone = Zone;

	// IP地址ipSections
	var IpSections = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('选择IP段'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formIpSections mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/ipaddress.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data && data.length){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.ipSections = IpSections;

	// 上网场景scene
	var Scene = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formScene mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/netScence.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setValue(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData().net;
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.scene = Scene;

	// 上网类型

	// 客户端client
	var Client = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('选择客户端'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formClient mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/client.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if(data){
				// 客户端
				var os = data.OSType; // 空数组为全选，null为不选
				var bs = data.BrowserType; // 空数组为全选，null为不选
				var ls = data.Language;
				var has =  ls && ls.length || os && os.length || bs && bs.length;

				if(has){
					this.list[1].click();
					this.$.detail.setData({
						os: os,
						bs: bs,
						ls: ls
					});
				}else{
					this.list[0].click();
				}
			}
			return this;
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.client = Client;

	// 自有人群people
	var NPeople = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formNPeople mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/treeSelect.popwin',
				{
					'target': doms.con,
					'url': 'category/people',
					'key': 'BdxId',
					'showTitle': false,
					'isPopwin': false,
					'param': {
						'url': 'category/people',
						'param': {
							'ChannelId': 10009,
							'Layer': 5
						}
					}
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.uiBind(this.list[2], 'change', 'changeStatue');
			this.changeStatue();
			if(this.$.detail){
				this.$.detail.load();
			}
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked') || this.list[2].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			var self = this;
			if(data){
				var PeopleValue = data.PeopleValue;
				var NPeople = data.NPeople || {};
				//转换字段
				NPeople = self.formatPeople(NPeople);
				if(NPeople.length){
					if(+PeopleValue){
						self.list[2].click();
					}else{
						self.list[1].click();
					}
				}else{
					self.list[0].click();
				}
				self.$.detail.setValue(NPeople);
			}

			return self;
		},
		getData: function(){
			var self = this;
			var data = {};
			// 自有人群
			data.PeopleValue = 0;
			data.NPeople = {};

			if (self.list[0].prop('checked')){
				return data;
			}else {
				if(self.list[2].prop('checked')){
					data.PeopleValue = 1;
				}
				data.NPeople.property = self.$.detail.getValue();
				return data;
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		},
		//自有人群，秒针人群的字段转化
		formatPeople: function(people){
			var result = [];
			var property = people.property || [],
				sex = people.sex || [];

			var SEXMAP = {
				'man': {
					'id': 51,
					'text': '男性'
				},
				'woman': {
					'id': 38,
					'text': '女性'
				}
			};

			util.each(property,function(value, key){
				result.push(value);
			});

			//男女字段转化
			util.each(sex, function(value, key){
				if(SEXMAP[value]){
					result.push({
						'id': SEXMAP[value]['id'],
						'text': SEXMAP[value]['text']
					});
				}
			});

			return result;
		}
	})
	exports.nPeople = NPeople;

	// 三方人群peopleTanx(不能用)
	var TBPeople = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formTBPeople mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/treeSelect.base',
				{
					'target': doms.con,
					'url': 'category/people',
					'param': {
						'ChannelId': 10004
					}

				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.tbPeople = TBPeople;

	// 秒针人群peopleMiaozhen(不能用)
	var MZPeople = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formMZPeople mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/treeSelect.base',
				{
					'target': doms.con,
					'url': 'category/people',
					'param': {
						'ChannelId': 10001
					}
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.mzPeople = MZPeople;

	// 其他人群peopleBiddingx(不能用)
	var BdxPeople = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formBdxPeople mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/treeSelect.base',
				{
					'target': doms.con,
					'url': 'PDMP/bdxPeople',
					'param': {
						'ChannelId': 168
					}
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.bdxPeople = BdxPeople;

	// 联通人群 peopleUnicom

	// 温度temperature
	var Temperature = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formTemperature mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/temperature.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.temperature = Temperature;

	// 湿度humidity
	var Humidity = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formHumidity mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/checkBoxGroup.base',
				{
					'target': doms.con,
					'items': [
						{'id':1, 'name':LANG('干燥（0% ~ 40%）')},
						{'id':2, 'name':LANG('舒适（40% ~ 70%）')},
						{'id':3, 'name':LANG('潮湿（70% ~ 100%）')}
					]
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.humidity = Humidity;

	// 空气指数aireIndex
	var AireIndex = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('包含以下条件'), value: 1},
					{text: LANG('排除以下条件'), value: 2}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formHumidity mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'modules/checkBoxGroup.base',
				{
					'target': doms.con,
					'items': [
						{'id':1, 'name':LANG('优（0 ~ 50）')},
						{'id':2, 'name':LANG('良（51 ~ 100）')},
						{'id':3, 'name':LANG('轻度污染（101 ~ 150）')},
						{'id':4, 'name':LANG('中度污染（151 ~ 200）')},
						{'id':5, 'name':LANG('重度污染（201 ~ 300）')},
						{'id':6, 'name':LANG('严重污染（300以上）')}
					]
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.aireIndex = AireIndex;

	// 温差TemperatureDiff
	var TemperatureDiff = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定温差'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formHumidity mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/temperatureDiff.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.temperatureDiff = TemperatureDiff;

	// 百度指数HotWord
	var HotWord = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('关闭'), value: 0, 'checked': true},
					{text: LANG('开启'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formHotWord mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/hotWord.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if (data){
				this.list[1].click();
				this.$.detail.setData(data);
			}else {
				this.list[0].click();
			}
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.hotWord = HotWord;

	// 视频定向 videoDirect

	// 设备类型 deviceType

	// 设备品牌 deviceBrand

	// 设备型号 deviceModel

	// 上网类型 network
	var Network = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('不限'), value: 0, 'checked': true},
					{text: LANG('指定'), value: 1}
				]
			});

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);

			var el = self.getDOM();
			var doms = self.$doms = {
				con: $('<div class="M-formScene mt15" />').appendTo(el).hide()
			};

			self.createAsync(
				'detail', 'campaign/modules/network.base',
				{
					'target': doms.con
				},
				'afterCreate'
			);
		},
		afterCreate: function(mod){
			this.uiBind(this.list[0], 'change', 'changeStatue');
			this.uiBind(this.list[1], 'change', 'changeStatue');
			this.changeStatue();
		},
		changeStatue: function(evt){
			var checked = this.list[1].prop('checked');
			this.$doms.con.toggle(checked);
		},
		setData: function(data){
			if(data){
				if(data.length){
					this.list[1].click();
					this.$.detail.setData({
						net: data
					});
				}else{
					this.list[0].click();
				}
			}
			return this;
		},
		getData: function(){
			if (this.list[0].prop('checked')){
				return null;
			}else {
				return this.$.detail.getData();
			}
		},
		reset: function(){
			if(this.get('detail')){
				this.get('detail').reset();
			}
			this.list[0].prop('checked');
			this.list[0].click();
		}
	})
	exports.network = Network;

	// 操作系统 clientMT

	// 三方监测
	var AMonitorUrl = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'value': '',
				'width': '40%',
				'height': 60,
				'view_model': {

				}
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM();

			var text = this.$text = $([
				 '<textarea cols="5" class="P-campaignEditInputWidth">',
				 '</textarea>'
			].join('')).appendTo(el);

			if(c.width){
				text.width(c.width);
			}
			if(c.height){
				text.height(c.height);
			}
		},
		getData: function(){
			var self = this;
			// 三方监测 (逗号分隔)
			var AMonitorUrl = self.$text.val().replace(/(\n)+|(\r\n)+|(；)/g, '\n').split('\n');
			var result = [];

			util.each(AMonitorUrl, function(item){
				if(util.trim(item)){
					result.push(util.trim(item));
				}
			});

			return result;
		},
		setData: function(data){
			var self = this;
			self.$text.val(data && data.length && data.join('\r') || '');
			return self;
		},
		reset: function(){
			var self = this;
			self.$text.val('');
			return self;
		}
	});
	exports.aMonitorUrl = AMonitorUrl;


	// 活动状态
	var Status = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('开启'), value: 1, 'checked': true},
					{text: LANG('暂停'), value: 2}
				]
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.status = Status;

	// 活动标签
	var Tag = taglabels.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'reqType': 'websocket',
				'hasLabel': false,
				'label': LANG('标签：'),
				'database': 'campaign/labels',
				'async': true,
				'tips': LANG('给活动贴上标签，方便管理。多个标签用“,”分开。')
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.tag = Tag;

	//------------------------------------------------------------------------

	// 自动优化的广告位出价
	var Channel = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'label': null,
				'value': 0, // 默认选中第一个
				'changeEvent': true,
				'autoChange': false,
				'eventWithoutChange': true,
				'setDataType': 'prop',
				'key': 'id',
				'name': 'name',
				'labelWidth': null,
				'labelHeight': 30
				//,'tips': LANG('即不同的AD-Exchange。')
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.channel = Channel;


	// 自动优化的广告位出价
	var RetainPrice = input.radio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'data': [
					{text: LANG('保留'), value: 0, 'checked': true},
					{text: LANG('删除'), value: 1}
				]
			});
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			self.Super('afterBuild', arguments);
		}
	});
	exports.retainPrice = RetainPrice;


	// 简版-添加素材
	var AddMaterial = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignAddMaterial',
				'limit': 0,
				'view_model': {

				}

			});

			this.$selectData = [];
			this.$selectMap = {};

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var el = self.getDOM();

			$([
				'<div>',
					'<span pub-name="select" pub-mod="@base/common/input.button"/>',
					// '<span pub-name="addNew" pub-mod="@base/common/input.button"/>',
				'</div>',
				'<div class="mt10">',
					'<span pub-name="grid" pub-mod="@base/grid.baseNoDate"/>',
				'</div>'
			].join('')).appendTo(el);


			self.buildFromTemplate({
				'select': {
					'value': LANG('选择创意包'),
					'class': 'btn btn-default mr20'
				},
				'addNew': {
					'value': LANG('新建创意包'),
					'class': 'btn btn-default'
				},
				'grid': {
					'sort': null,
					'hasTab': false,
					'hasPager': false,
					'hasAmount': false,
					'hasExport': false,
					'hasSearch': false,
					'cols': [
						{name:'_id',text:"ID", sort: true, align: 'center', width: 80},
						'SweetyNameWithThumb',
						{name: 'whisky', text: LANG('落地页'), render: 'renderWhisky', width:480, align:'left', sort: false}
					],
					'list':{
						'rowSelect': true,
						'scroll_type': 'row',
						'scroll_size': 30,
						'css': {
							'min-width': '830px',
							'overflow': 'auto'
						}
					},
					'operation': {
						'render': 'renderOperation',
						'cls': 'M-gridOPCursor',
						'width': 80
					}
				}
			});
		},
		renderWhisky: function(i, val, data, con){
			var self = this;
			var html = $('<div/>');
			var id = data._id;
			var whiskyInput = self.get('whiskyInput'+id);

			if(whiskyInput){
				whiskyInput.destroy();
			}
			whiskyInput = self.create('whiskyInput'+id, input.flexibleInput, {
				'target': html,
				'width': 400,
				'placeholder': 'http://'
			}).setData(data.WhiskyPaths || []);

			if(self.$selectMap[id]){
				self.$selectMap[id].WhiskyInput = whiskyInput;
			}

			return html;
		},
		// 渲染操作列
		renderOperation: function(i, val, data, con){
			var html = '';

			html = [
				'<a data-op="remove" data-id="'+data.id+'">'+LANG("删除")+'</a>'
				// '<a data-op="edit" data-id="'+data.id+'">'+LANG("编辑")+'</a>',
				// '<a data-op="copy" data-id="'+data.id+'">'+LANG("复制")+'</a>'
			];

			return html.join(' | ');
		},
		onListOpClick: function(ev){
			switch (ev.param.op){
				case 'remove':
					this.removeSweetyGridItem(ev.param.data._id);
					break;
				case 'edit':

					break;
				case 'copy':

					break;
			}
		},
		onInputClick: function(ev){
			if(ev.name == 'select'){
				this.selectSweety();
			}
			return false;
		},
		// 构建弹层
		selectSweety: function(){
			var self = this;
			var c = self.getConfig();
			var dlg = self.$.selectSweety;
			if(!dlg){
				self.createAsync('selectSweety', 'sweety/popwin/selectSweety.mainLite', {
				}, function(mod){
					mod.switchToSelect().show().load().setSelectData(self.getPathsValue());
				});
			}else{
				dlg.switchToSelect().show().load().setSelectData(self.getPathsValue());
			}
		},
		// 响应创意包消息
		onSelectSweetyGroup: function(ev) {
			var self = this;
			if(ev && ev.param){
				util.each(ev.param, function(item){
					if(item){
						self.$selectMap[item._id] = item;
					}
				});
			}

			self.addSweetyGrid();
			return false;
		},
		// 删除表格数据一条
		removeSweetyGridItem: function(id){
			var self = this;
			if(id){
				self.$selectMap[id] = null;
				self.addSweetyGrid();
			}
		},
		// 设置表格setData
		addSweetyGrid: function(data){
			var self = this;
			var grid = self.$.grid;

			if(grid){
				// 转换为数组，设置表格数据
				var data = [];
				util.each(self.$selectMap, function(item){
					if(item){
						data.push(item);
					}
				});
				grid.setData(data);
			}
		},
		// 获取填写落地页的路径
		getPathsValue: function(){
			var self = this;
			var data = [];
			util.each(self.$selectMap, function(item){
				if(item){
					if(item.WhiskyInput){
						item.WhiskyPaths = item.WhiskyInput.getData();
					}
					data.push(item);
				}
			});
			return data;
		},
		getData: function(){
			var self = this;
			var data = self.getPathsValue();
			var Sweetys = [];
			var WhiskyCreatives = [];
			util.each(data, function(item, idx){
				if(item){
					if(item.WhiskyPaths && item.WhiskyPaths.length){
						Sweetys.push({
							'Id': item._id,
							'RatioSet': 100,
							'WhiskyPaths': item.WhiskyPaths || []
						});
						util.each(item.WhiskyPaths, function(path){
							WhiskyCreatives.push({
								'Path': path,
								'RatioSet': 100
							});
						});
					}
				}
			});
			var result = [{
				Id: 0,
				ServerId: 0,
				RatioSet: 100,
				Sweetys: Sweetys,
				WhiskyCreatives: WhiskyCreatives,
				SweetyRatioType: 0,
				WhiskyCreativeRatioType: 0
			}];

			return result;
		},
		setData: function(data){
			var self = this;
			if(data && data.length == 1){
				if(data[0].Sweetys && data[0].WhiskyCreatives){
					util.each(data[0].Sweetys, function(item, idx){
						if(item){
							item._id = item.Id;
							self.$selectMap[item._id] = item;
						}
					});
				}
				self.addSweetyGrid();
			}
			return self;
		},
		validate: function(){
			var data = this.getData();
			if(data && data.length && data[0]){
				if(!data[0].Sweetys.length || !data[0].WhiskyCreatives.length){
					pubjs.alert(LANG('请添加素材'));
					return false;
				}
			}
			return true;
		},
		reset: function(){
			var self = this;
			self.$selectMap = {};
			self.$.grid.setData([]);
			return self;
		}
	});
	exports.addMaterial = AddMaterial;

	// 简版-广告点击类型
	var LandType = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignLandType',
				'view_model': {
					'showApp': false,
					'AppPackName': ''
				}

			});
			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var el = self.getDOM();

			$([
				'<div class="M-formConGroup">',
					'<label class="group-label">'+LANG('广告点击类型：')+'</label>',
					'<div class="group-content">',
						'<span pub-name="LandType" pub-mod="@base/common/drop.drop"></span>',
					'</div>',
				'</div>',

				'<div class="M-formConGroup" ms-visible="showApp">',
					'<label class="group-label name">'+LANG('应用包名：')+'</label>',
					'<div class="group-content" >',
						'<input type="text" ms-duplex="AppPackName" class="w40pct">',
						'<span class="ml15" pub-name="AppPackNameTip" pub-mod="@base/tip.desc"/>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);


			self.buildFromTemplate({
				'LandType': {
					'def': LANG('选择类型'),
					'width': 200,
					'value': 0,
					'options': [
						{'id': 0, 'name': LANG('打开网页')},
						{'id': 1, 'name': LANG('下载ios应用')},
						{'id': 2, 'name': LANG('下载android应用')}
					],
					'panel_config': {
						'hasSearch': false,
						'appendTo': 'relative'
					}
				},
				'AppPackNameTip': {
					'width': 300,
					'data': LANG('非文件名称，具体内容请联系APP的开发人员')
				}
			});
		},
		onDropChange: function(ev){
			if(ev.name == 'LandType') {
				this.vm.$.showApp = +ev.param.id == 2;
			}
		},
		getData: function(){
			var self = this;
			var vm = self.vm.$;
			var data = {};
			data.LandType = +self.$.LandType.getValue(true).id;
			data.AppPackName = data.LandType == 2 ? vm.AppPackName : '';
			return data;
		},
		setData: function(data){
			var self = this;
			if(data){
				self.$.LandType.setValue(data.LandType);
				self.vm.$.AppPackName = data.AppPackName || '';
			}
			return self;
		},
		reset: function(){
			var self = this;
			self.$.LandType.setValue(0);
			self.vm.$.AppPackName = '';
			return self;
		}
	});
	exports.landType = LandType;

	// 活动智能监控模块
	var CampaignMonitor = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-adminSmartCampaignMonitor',
				'vModel': {
					// 智能监控raido  0:关闭 1:引用监控设置
					'SmartMonitorAction': 0,
					'hasCreateBtn': pubjs.checkRight('monitor.addAlarm')
				}
			});

			this.Super('init', arguments);
		},
		afterBuild:function(){
			var self = this;
			// var c = self.getConfig();

			self.append($([
				'<div class="M-formSectionItem">',
					'<label>',
						'<input type="radio" v-model="SmartMonitorAction" value="0">',
						'<span class="pl4 pr4">'+LANG('关闭')+'</span>',
					'</label>',
					'<label>',
						'<input type="radio" v-model="SmartMonitorAction" value="1">',
						'<span class="pl4 pr4">'+LANG('引用监控设置')+'</span>',
					'</label>',
				'</div>',
				'<span class="ml15" pub-name="smartMonitorTip" pub-mod="@base/tip.desc"/>',
				'<div class="mt10" pub-name="smartMonitorCreateBtn" pub-mod="@base/common/input.button" v-show="SmartMonitorAction==1" ms-if="hasCreateBtn"/>',
				'<div v-show="SmartMonitorAction==1" class="mt10" pub-name="grid" pub-mod="admin/smartMonitor/grid/grid.campaginMonitorList"/>'
			].join('')));

			self.vm.mount();

			var param = {};
			var advId = +util.getQueryString('aderId');
			if(advId) {
				param.AdvertiserId = [advId];
			}

			var config = {
				'smartMonitorTip': {
					width: 300,
					data: LANG('开启智能监控后，系统可在满足所定义的条件时自动发送提醒邮件、发系统消息，避免造成损失。多个条件之间是“或”的关系。')
				},
				'smartMonitorCreateBtn': {
					'value': LANG('新建监控'),
					'class': 'btn btn-default mr20',
					'width': null
				},
				'grid': {
					param: param
				}
			};
			
			self.buildFromTemplate(config);
		},
		afterBuildTemplate: function(mod, data){
			var grid = this.$.grid;
			var filter = grid.getContainer("filter");

			var showSelected = $([
				'<label class="cur_p">',
					'<input type="checkbox" class="valign-2"/>',
					'<span>' + LANG('显示已选') + '</span>',
				'</label>'
			].join(''));
			showSelected.appendTo(filter);
			this.uiBind(showSelected, 'click', 'eventShowSelected');
		},
		// 显示已选
		eventShowSelected: function(evt, elm){
			var grid = this.$.grid;
			var isChecked = $(elm).find('input').prop('checked');
			var selected = grid.getSelectRowIds();

			var ids = isChecked ? selected : null;
			grid.setParam({
				'Ids': ids
			}, true);
			grid.load();
		},
		onInputClick: function(ev){
			switch (ev.name){
				case 'smartMonitorCreateBtn':
					this.showCreatePop();
					break;
			}
			return false;
		},
		showCreatePop: function(){
			var self = this;
			var mod = self.$.createPop;
			if(!mod){
				self.createAsync('createPop', 'admin/smartMonitor/popwin/popwin.createMonitor',
					{},
					function(module){
						if(module){
							module.show();
						}
					}
				)
			}else{
				mod.show();
			}
		},
		onSaveMonitorPopSuccess: function(ev){
			this.$.grid.load();
			return false;
		},
		setData: function(data){
			var vm = this.vm.$;
			var cs = this.$;
			// 智能监控状态 0:关闭 1:引用监控设置
			vm.SmartMonitorAction = data.Action || 0;
			// 智能监控
			cs.grid.setSelectRowIds(data.Ids);
			return this;
		},
		getData: function(){
			var cs = this.$;
			var data = {};
			// 智能监控
			// 智能监控状态 0:关闭 1:引用监控设置
			data.Action = +this.vm.get('SmartMonitorAction') || 0;
			data.Ids = cs.grid.getSelectRowIds();
			return data;
		},
		reset: function(){
			this.vm.reset();
			this.$.grid.setSelectRowIds([]);
			return this;
		}
	});
	exports.campaignMonitor = CampaignMonitor;
});